﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="LightBoxGallery.ascx.cs" Inherits="WebUI.Controls.LightBoxGallery" %>

<script type="text/javascript">
    function deletePicture(id) {
        if (confirm("Are you sure to delete this image?")) {
            var hid = document.getElementById("<%= hidSelectedPic.ClientID %>");
            hid.value = id;
            var btn = document.getElementById("<%= btnDeletePic.ClientID %>");
            btn.click();

            return false;
        }
    }

    function btnSetDefault(id) {
        var hid = document.getElementById("<%= hidSelectedPic.ClientID %>");
        hid.value = id;
        var btn = document.getElementById("<%= btnSetDefault.ClientID %>");
        btn.click();

        return false;
    }

    function renamePicture(id) {
        var hid = document.getElementById("<%= hidEditId.ClientID %>");
        hid.value = id;
        var btn = document.getElementById("<%= btnRefresh.ClientID %>");
        btn.click();

        return false;
    }

    function saveName(id) {
        var hid = document.getElementById("<%= hidNewName.ClientID %>");
        
        var btn = document.getElementById("<%= btnSaveName.ClientID %>");
        btn.click();

        return false;
    }

    function txtDesc_onBlur(txt) {
        var hid = document.getElementById("<%= hidNewName.ClientID %>");
        hid.value = txt.value;
    }
</script>

<asp:DataList ID="rptImages" runat="server" >
    <ItemTemplate>
        <div class='<%# (Eval(DefaultField) == DBNull.Value || (bool)Eval(DefaultField) == false) ? "galleryItem" : "gallerySelectedItem" %>'>
            <div>
                <asp:LinkButton runat="server" OnClientClick='<%# "return deletePicture(" + Eval(IDField) + ");" %>' title="Delete" style="cursor:pointer">
                    <img id="Img1" runat="server" src="~/Images/Delete.gif" alt="Delete" />
                </asp:LinkButton>
                <asp:LinkButton runat="server" OnClientClick='<%# "return btnSetDefault(" + Eval(IDField) + ");" %>' title="Set Default" style="cursor:pointer" visible='<%# (Eval(DefaultField) == DBNull.Value || (bool)Eval(DefaultField) == false) ? true : false %>'>
                    <img id="Img2" runat="server" src="~/Images/Check.png" alt="Set Default" />
                </asp:LinkButton>
                <asp:LinkButton runat="server" OnClientClick='<%# "return renamePicture(" + Eval(IDField) + ");" %>' title="Rename" style="cursor:pointer" visible='<%# hidEditId.Value != Eval(IDField).ToString() %>'>
                    <img id="Img3" runat="server" src="~/Images/Edit.gif" alt="Rename" />
                </asp:LinkButton>
                <asp:LinkButton runat="server" OnClientClick='<%# "return saveName(" + Eval(IDField) + ");" %>' title="Save" style="cursor:pointer" visible='<%# hidEditId.Value == Eval(IDField).ToString() %>'>
                    <img id="Img4" runat="server" src="~/Images/save.gif" alt="Save" />
                </asp:LinkButton>
            </div>
            <div style="text-align:left;vertical-align:top">
                <a runat="server" href='<%# POSSystem.BLL.Utilities.GetProductImageUrl(Eval(OriginalField)) %>' rel="lightbox[roadtrip]" title='<%# Eval(DescriptionField) %>'>
                    <img style="border:none" runat="server" src='<%# POSSystem.BLL.Utilities.GetProductImageUrl(Eval(ThumbField)) %>' alt='<%# Eval(DescriptionField) %>' />
                </a>
            </div>
            <div style="text-align:center; width:100%; background-color:Gray; height:16px; margin-bottom:1px">
                <asp:Literal Visible='<%# hidEditId.Value != Eval(IDField).ToString() %>' ID="lblDesc" Text='<%# Eval(DescriptionField) == DBNull.Value ? "n/a" :  (Eval(DescriptionField).ToString().Length > 12 ? Eval(DescriptionField).ToString().Substring(0, 12) + "..." : Eval(DescriptionField).ToString()) %>' runat="server"></asp:Literal>
                <asp:TextBox Width="98px" Height="15px" BorderStyle="None" BorderWidth="0px" onblur="txtDesc_onBlur(this);" Visible='<%# hidEditId.Value == Eval(IDField).ToString() %>' ID="txtDesc" Text='<%# Eval(DescriptionField).ToString() %>' runat="server"></asp:TextBox>
            </div>
        </div>
    </ItemTemplate>
</asp:DataList>
<asp:Label class='labelHint' ID="lblNoRecord" runat="server" Text="No item to display." Visible="false"></asp:Label>
<asp:HiddenField ID="hidSelectedPic" runat="server" />
<asp:HiddenField ID="hidEditId" runat="server" />
<asp:HiddenField ID="hidNewName" runat="server" />
<asp:Button ID="btnDeletePic" runat="server" OnClick="btnDeletePic_OnClick" style='display:none' />
<asp:Button ID="btnSetDefault" runat="server" OnClick="btnSetDefault_OnClick" style='display:none' />
<asp:Button ID="btnRefresh" runat="server" OnClick="btnRefresh_OnClick" style='display:none' />
<asp:Button ID="btnSaveName" runat="server" OnClick="btnSaveName_OnClick" style='display:none' />